﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using W.Purchase.Domain;
using W.Purchase.Domain.PageDTO;
using W.Purchase.Read.API.AppLication.Command.Command;

namespace W.Purchase.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ClientController : ControllerBase
    {
        private readonly IMediator mediator;
        public ClientController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 显示客户信息
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<PageInfo>> ShowClient([FromQuery] ClientShowCommand command)
        {
            ApiResult<PageInfo> list = new ApiResult<PageInfo>();
            try
            {
                list.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                list.Code = -1;
                list.Message = ex.Message;
                throw;
            }
            return list;
        }
        /// <summary>
        /// 显示联系人
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ApiResult<List<Contact>>> ShowContact([FromQuery] ContactShowCommand command)
        {
            ApiResult<List<Contact>> list= new ApiResult<List<Contact>>();
            try
            {
                list.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                list.Code = -1;
                list.Message = ex.Message;
                throw;
            }
            return list;
        }
        /// <summary>
        /// 显示客户名称
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<Client>>> GetResult()
        {
            return await mediator.Send(new ClientNameShowCommand());
        }
    }
}
